package com.yc.common.constant;

import io.jsonwebtoken.Claims;

import java.util.Locale;

/**
 * 通用常量信息类
 * 优化版本
 *
 * 对常量按功能分类组织，提高可读性与可维护性
 * @author yc
 */
public class Constant {

    /** 字符集相关常量 */
    public static class Charset {
        public static final String UTF8 = "UTF-8";
        public static final String GBK = "GBK";
        public static final Locale DEFAULT_LOCALE = Locale.SIMPLIFIED_CHINESE;
    }

    /** 请求协议相关常量 */
    public static class Protocol {
        public static final String HTTP = "http://";
        public static final String HTTPS = "https://";
        public static final String LOOKUP_RMI = "rmi:";
        public static final String LOOKUP_LDAP = "ldap:";
        public static final String LOOKUP_LDAPS = "ldaps:";
    }

    /** HTTP状态码 */
    public static class HttpStatus {
        public static final int SUCCESS = 200;
        public static final int FAIL = 500;
    }

    /** 登录相关常量 */
    public static class Status {
        public static final String SUCCESS_STATUS = "0";
        public static final String FAIL_STATUS = "1";
        public static final String SUCCESS_MESSAGE = "Success";
        public static final String FAIL_MESSAGE = "Error";
        public static final String LOGOUT = "Logout";
        public static final String REGISTER = "Register";
    }

    /** 权限相关 */
    public static class Permissions {
        public static final String ALL_PERMISSION = "*:*:*";
        public static final String SUPER_ADMIN = "admin";
        public static final String ROLE_DELIMETER = ",";
        public static final String PERMISSION_DELIMETER = ",";
    }

    /** 分页相关常量 */
    public static class Pagination {
        public static final String PAGE_NUM = "pageNum";
        public static final String PAGE_SIZE = "pageSize";
        public static final String ORDER_BY_COLUMN = "orderByColumn";
        public static final String IS_ASC = "isAsc";
    }

    /** 验证码相关常量 */
    public static class Captcha {
        // Redis中验证码的key前缀
        public static final String EMAIL_CODE_PREFIX = "email:code:";
        // 验证码有效期（分钟）
        public static final int CODE_EXPIRE_MINUTES = 3;
        // 邮件主题
        public static final String EMAIL_SUBJECT = "验证码";
        // 邮件内容模板
        public static final String EMAIL_CONTENT_TEMPLATE = "您的验证码是：%s，有效期%d分钟，请勿泄露给他人。";
    }

    /** 认证相关 */
    public static class Authentication {
        public static final Integer CAPTCHA_EXPIRATION = 2;
        public static final String TOKEN = "token";
        public static final String TOKEN_PREFIX = "Bearer ";
        public static final String LOGIN_USER_KEY = "login_user_key";
        public static final String JWT_USERID = "userid";
        public static final String JWT_USERNAME = Claims.SUBJECT;
        public static final String JWT_AVATAR = "avatar";
        public static final String JWT_CREATED = "created";
        public static final String JWT_AUTHORITIES = "authorities";
    }

    /** 资源相关常量 */
    public static class Resource {
        public static final String PREFIX = "/profile";
    }

    /** 安全相关常量 */
    public static class Security {
        public static final String[] JSON_WHITELIST = {"org.springframework", "com.yc"};
        public static final String[] JOB_WHITELIST = {"com.yc.job.task"};
        public static final String[] JOB_BLACKLIST = {
                "java.net.URL",
                "javax.naming.InitialContext",
                "org.yaml.snakeyaml",
                "org.springframework",
                "org.apache",
                "com.yc.common.core.utils.file"
        };
    }
}
